<template>
  <div>
    <!-- 轮播图 -->
    <van-swipe class="my-swipe" :autoplay="3000" :loop="false">
      <van-swipe-item
        v-for="carouse in swiper"
        :key="carouse.cid"
        indicator-color="white"
      >
        <van-image :src="carouse.img">
          <template v-slot:loading>
            <van-loading type="spinner" size="20" />
          </template>
        </van-image>
      </van-swipe-item>
    </van-swipe>
    <!-- 商品 -->
    <van-card
      v-for="(item, index) in getgoods"
      :key="index"
      num="2"
      :price="item.original_price"
      :desc="item.desc"
      :title="item.pname"
      :thumb="item.imgUrl"
    />
  </div>
</template>

<script lang="ts">
import { defineComponent, ref, onMounted } from "vue";
import { HomeuserServe } from "../../api/home";
import { HomeMent } from "../../interfase/module/home";

export default defineComponent({
  name: "Home",
  setup() {
    const homeserve = HomeuserServe();
    const state = {
      swiper: ref<Array<HomeMent.HomeSwiper>>([]),
      getgoods: ref<Array<HomeMent.Homegoods>>([]),
    };
    const getSwiper = async () => {
      const result = await homeserve.getswiper({});
      state.swiper.value = result.result;
    };
    const getGoods = async () => {
      const result = await homeserve.getGoods({});
      state.getgoods.value = result.result;
    };
    onMounted(() => {
      getSwiper();
      getGoods();
    });
    return {
      ...state,
    };
  },
});
</script>

<style lang="less" scoped>
.my-swipe .van-swipe-item {
  color: #fff;
  font-size: 20px;
  line-height: 150px;
  text-align: center;
  background-color: #39a9ed;
  height: 100%;
}
</style>
